//
//  YYT_LoginView.m
//  AudioVisualFeast
//
//  Created by 温晓宇 on 16/1/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YYT_LoginView.h"

@interface YYT_LoginView ()

@property (nonatomic, strong)UILabel *userLabel;

@property (nonatomic, strong)UILabel *passwordLabel;

@property (nonatomic, strong)UIButton *loginButton;
@property (nonatomic, strong)UIButton *regisButton;

@end

@implementation YYT_LoginView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}
-(void)create{
    self.userLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 130, 100, 65, 30)];
    [self initLabel:_userLabel Text:@"用户名:"];
    
    self.userText = [[UITextField alloc] initWithFrame:CGRectMake(WIDTH / 2 - 40, 100, 150, 30)];
    _userText.placeholder = @"请输入用户名";
    [self initText:_userText];
    
    self.passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 2 - 130, 150, 65, 30)];
    [self initLabel:_passwordLabel Text:@"密码:"];
    
    self.passwordText = [[UITextField alloc] initWithFrame:CGRectMake(WIDTH / 2 - 40, 150, 150, 30)];
    _passwordText.placeholder = @"请输入密码";
    _passwordText.secureTextEntry = YES;
    [self initText:_passwordText];
    
    self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _loginButton.frame = CGRectMake(WIDTH / 2 - 130, 250, 100, 50);
    _loginButton.backgroundColor = [UIColor greenColor];
    [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [_loginButton addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_loginButton];
    
    self.regisButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _regisButton.frame = CGRectMake(WIDTH / 2 + 10, 250, 100, 50);
    _regisButton.backgroundColor = BLACK_COLOR;
    [_regisButton setTitle:@"注册" forState:UIControlStateNormal];
    [_regisButton addTarget:self action:@selector(regisButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_regisButton];
    
}
//dismiss登录页面/传数据
- (void)loginButton:(UIButton *)btn{
    [self.delegate login];
}
//跳到注册页面
- (void)regisButton:(UIButton *)btn{
    [self.delegate regis];
}

- (void)initText:(UITextField *)text{
    text.layer.borderColor = BLACK_COLOR.CGColor;
    text.layer.borderWidth = 1;
    text.layer.cornerRadius = 5;
    text.layer.masksToBounds = YES;
    text.backgroundColor = [UIColor redColor];
    [self addSubview:text];
}

- (void)initLabel:(UILabel *)label Text:(NSString *)text{
    label.text = text;
    label.backgroundColor = [UIColor redColor];
    [self addSubview:label];
}

@end
